from django.http import JsonResponse
from django.shortcuts import render
from django.http import HttpResponse
from .models import *
# Create your views here.
from django.views import View


class IndexView(View):
    def get(self,request):
        return render(request,'index.html')


def GetView(request):
    name = request.POST.get('uname')
    pwd = request.POST.get('pwd')
    print(name,pwd)
    return JsonResponse({'flag':True})


def only(request):
    return render(request,'only.html')


def isonly(request):
    #接受参数
    uname = request.GET.get('uname','')
    pwd = request.GET.get('pwd','')
    #判断数据是否存在
    user = Stu.objects.filter(sname=uname)
    if user:
        return JsonResponse({'flag':1})
    else:
        return JsonResponse({'flag':0})